package org.cqu_proj.demo.dao;

import org.cqu_proj.demo.entity.Movie;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;
import java.util.Optional;

public interface MovieRepository extends MongoRepository<Movie, String> {

    // 使用 Pageable 支持分页查询
    Page<Movie> findAll(Pageable pageable);

    Movie findBymovieId(int movieId);

    // 根据 genres 筛选并按评分排序分页
    @Query("{ 'genres': { $regex: ?0, $options: 'i'  },'ratingCount': { $gte: ?1 } }")
    List<Movie> findMoviesByGenresSortedByAvgRatingDesc(String genresRegex, int minRatingCount,Pageable pageable);

    // 查询所有电影按评分排序分页
    @Query("{ 'ratingCount': { $gte: ?0 } }")
    List<Movie> findAllByOrderByAvgRatingDesc(int minRatingCount,Pageable pageable);

    List<Movie> findAllByMovieIdIn(List<Integer> movieIds);
}
